﻿import com.crystalcentral.model.*;
import com.crystalcentral.util.*;

class com.crystalcentral.model.DiyInfo 
{
	var items:Array;
	var comments:String;
	var zoomScale:Number;
	var scrollX:Number;
	var scrollY:Number;
	var version:Number;
	
	function DiyInfo(xml:XML) {
		init(xml);
	}
	
	function init(xml:XML) {
		items = new Array();
		
		var setting = xml.firstChild.firstChild;
		this.version = setting.attributes["version"] == undefined ? 1 : Number(setting.attributes["version"]);
		
		var str:String = new String(setting.firstChild.firstChild);
		if (setting.firstChild.firstChild == undefined) {
			str = "";
		}
		str = StringTool.replace(str, "&lt;","<");
		str = StringTool.replace(str, "&gt;",">");
		str = StringTool.replace(str, "&amp;","&");
		str = StringTool.replace(str, "&quot;","\"");
		str = StringTool.replace(str, "&apos;","'");
		this.comments = (str == "Add your own comments") ? "" : str;
		
		var position = setting.childNodes[1].attributes;
		this.zoomScale = Number(position["zoomScale"]);
		this.scrollX = Number(position["scrollX"]);
		this.scrollY = Number(position["scrollY"]);
		trace("zoomScale: "+zoomScale);
		trace("scrollX: "+scrollX);
		trace("scrollY: "+scrollY);
		trace("version: "+version);
		
		var objectlist = setting.nextSibling;
		for (var i = 0; i < objectlist.childNodes.length; i++) {
			var object = objectlist.childNodes[i];
			var attr = object.attributes;
			if (object.nodeName != "object" || (attr["tag"] == "image" && attr["src"] == "images/product.png"))
				continue;
			
			var obj = (attr["tag"] == "image") ? new DiyImageItem(object) : new DiyTextItem(object);			
			items.push(obj);
		}
	}
}